<extend name="Public/layout" />

<block name="style">
    <link rel="stylesheet" type="text/css" href="__ADMIN__/assets/ztree/css/ztree.css" />
</block>

<block name="content">
    <section class="wrapper site-min-height">
        <!-- page start-->
        <div class="row">

            <div class="col-md-12">
                <section class="panel">
                    <header class="panel-heading">
                        设置角色权限
                    </header>
                    <div class="panel-body">
                        <div class="zTreeDemoBackground left">
                            <ul id="auth_tree" class="ztree"></ul>
                        </div>
                    </div>

                    <form action="{:U('Admin/AdminRole/rule')}" method="post" class="ajax-from-submit ">
                        <input name="id" type="hidden" value="{$Think.get.id}">
                        <input id="rule" name="rules" type="hidden" value="">
                        <div class="panel-body">
                            <button class="btn btn-primary btn-sm  ajax-form-btn">
                                提交
                            </button>
                        </div>
                    </form>
                </section>
            </div>

            </div>
        </div>
        <!-- page end-->
    </section>
</block>

<block name="javascript">
    <!--<script  src="__ADMIN__/assets/ztree/js/jquery-1.4.4.min.js"></script>-->
    <script src="__ADMIN__/assets/ztree/js/jquery.ztree.core.js"></script>
    <script src="__ADMIN__/assets/ztree/js/jquery.ztree.excheck.js"></script>

    <script type="text/javascript">
        var setting = {
            check: {
                enable: true,
                chkboxType:{ "Y" : "ps", "N" : "ps" }
            },
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback:{
                onCheck:onCheck
            }
        };

        var zNodes =[
            <volist name="menu" id="vo">
                {
                    id:{$vo.id},
                    pId:{$vo.pid},
                    name:'{$vo.title}',
                    open:true,
                    checked:{$vo['checked']?'true':'false'},
                },
            </volist>
        ];
        //初始化节点
        $(document).ready(function(){
            $.fn.zTree.init($("#auth_tree"),setting, zNodes);
        });
        //回调设置
        function onCheck(e,treeId,treeNode) {
            var treeObj = $.fn.zTree.getZTreeObj("auth_tree"),
                    nodes = treeObj.getCheckedNodes(true),
                    v = "";
            for (var i = 0; i < nodes.length; i++) {
                v += nodes[i].id + ",";
            }
            $("#rule").val(v);
        }
        //菜单高亮
        MenuHighlight('{:U("Admin/AdminRole/index")}');
    </script>
</block>